// Learn cc.Class:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
//  - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html

var util = require('Utils');
var comps = require('ComponentDifine');
var RoomPlayerInfo = require('RoomPlayerInfo');

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        playerPos: [cc.Node],

        playerInfo: {
            default: null,
            type: cc.Prefab
        },

        mjTiles: {
            default: null,
            type: cc.Prefab
        },

        readyPlay: {
            default: null,
            type: cc.Prefab
        },

        readySign: {
            default: null,
            type: cc.Prefab
        }

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        //var pos = cc.p(-640, -360);

        var scene = cc.director.getScene();

        this.playerInfo = cc.instantiate(App.playAssets[comps.roomPlayerInfo]);
        scene.addChild(this.playerInfo);
        //this.playerInfo.parent = this.node;
        //this.playerInfo.setPosition(pos);

        this.readyPlay = cc.instantiate(App.playAssets[comps.roomReadyPlay]);
        scene.addChild(this.readyPlay);
        // this.readyPlay.parent = this.node;
        // this.readyPlay.setPosition(pos);

        this.readySign = cc.instantiate(App.playAssets[comps.roomReadySign]);
        scene.addChild(this.readySign);
        // this.readySign.parent = this.node;
        // this.readySign.setPosition(pos);

        this.mjTiles = cc.instantiate(App.playAssets[comps.roomMjTiles]);
        scene.addChild(this.mjTiles);
        // this.mjTiles.parent = this.node;
        // this.mjTiles.setPosition(pos);

        for (var i = 0; i < this.playerPos.length; i++) {
            var p = this.playerPos[i];
            p.active = false;            
        }

        var info = {
            nick: 'user1',
        };

        this.playerInfo.getComponent('RoomPlayerInfo').reOrder();
        this.playerInfo.getComponent('RoomPlayerInfo').setInfo(0, info);
    },

    componentAdded: function () {
        console.log('component added.');
    },

    start() {

    },

    // update (dt) {},
});
